/*
 * Copyright 2018-present KunMinX
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.nsgf.library.ui.adapter;

import android.content.Context;
import android.graphics.Color;

import androidx.recyclerview.widget.RecyclerView;

import com.kunminx.binding_recyclerview.adapter.SimpleDataBindingAdapter;
import com.nsgf.library.R;
import com.nsgf.library.data.bean.LibraryInfo;
import com.nsgf.library.databinding.ItemNsgfHomeSheetBehaviorBinding;
import com.nsgf.library.utils.StringUtil;
import com.nsgf.library.utils.UnitTo;

/**
 * Create by GC at 24/11/19
 */
public class HomeLabeRegionlListAdapter extends SimpleDataBindingPositionAdapter<LibraryInfo, ItemNsgfHomeSheetBehaviorBinding> {

    public HomeLabeRegionlListAdapter(Context context) {
        super(context, R.layout.item_nsgf_home_sheet_behavior, DiffUtils.getInstance().getLibraryInfoItemCallback());

    }

    @Override
    protected void onBindItem(ItemNsgfHomeSheetBehaviorBinding binding, LibraryInfo item, ViewHolder holder, int position) {
        binding.setVm(item);

        switch (position) {
            default:
                binding.llItemNsgfReginWater.setBackgroundResource(R.drawable.bg_home_sheet_behavior_test);
                break;
            case 1:
                binding.llItemNsgfReginWater.setBackgroundResource(R.drawable.bg_home_sheet_behavior_tow);
                break;
            case 2:
                binding.llItemNsgfReginWater.setBackgroundResource(R.drawable.bg_home_sheet_behavior_three);
                break;
            case 3:
                binding.llItemNsgfReginWater.setBackgroundResource(R.drawable.bg_home_sheet_behavior_four);
                break;
        }

        if (!StringUtil.isEmpty(item.getCurrentWaterLevel()) && !StringUtil.isEmpty(item.getFloodControl())) {

            if (Double.parseDouble(item.getCurrentWaterLevel()) > Double.parseDouble(item.getFloodControl())) {
                binding.tvItemWaterLevel.setTextColor(Color.parseColor("#F53F3F"));
            } else {
                binding.tvItemWaterLevel.setTextColor(Color.parseColor("#1D2129"));
            }
        }


    }
}
